package com.xiaor.rssevent.controller;

import com.xiaor.rssevent.service.EventService;
import com.xiaor.rssmodel.model.Event;
import com.xiaor.rssutils.pager.Page;
import com.xiaor.rssutils.result.ResultInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/event")
public class EventController {
    @Autowired
    private EventService eventService;
    @Autowired
    private ResultInfo info;
    private static Logger logger = LoggerFactory.getLogger(EventController.class);

    @ModelAttribute
    public void init() {
        info.clear();
        logger.info("/event");
    }

    @GetMapping("/find_by_name")
    ResultInfo findByName(Event event) {
        try {
            info.setData(eventService.findByName(event));
        } catch (Exception e) {
            e.printStackTrace();
            logger.info("findAll|查询失败");
        }
        return info;
    }

    @GetMapping("/find_all")
    ResultInfo findAll(Page page) {
        try {
            info.setData(eventService.findAll(page));
        } catch (Exception e) {
            e.printStackTrace();
            logger.info("findAll|查询失败");
        }
        return info;
    }

    @GetMapping("/find_simple_all")
    ResultInfo findSimpleAll(Page page) {
        try {
            info.setData(eventService.findSimpleAll(page));
        } catch (Exception e) {
            e.printStackTrace();
            logger.info("findSimpleAll|查询失败");
        }
        return info;
    }
}
